﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.Mobile.ContainerModel;

namespace QuickStart
{
	public class CrmModule : IContainerModule
	{
		ITaskService tasks;

		public CrmModule(ITaskService tasks)
		{
			this.tasks = tasks;
		}

		public void Configure(Container container)
		{
			// Register repository, presenter and view types.

			container.Register<ICustomerRepository>(
					c => new MemoryCustomerRepository())
				.InitializedBy((c, r) =>
				{
					// Initialize with some fake data.
					r.Create(new Customer { FirstName = "Joe", LastName = "Doe" });
					r.Create(new Customer { FirstName = "Sarah", LastName = "Smith" });
					r.Create(new Customer { FirstName = "Mary", LastName = "Brown" });
				});

			container
				.Register<IEditCustomersView>(
					c => new EditCustomersView())
				.InitializedBy(
					(c, v) => v.Presenter = c.Resolve<EditCustomersPresenter>())
				.ReusedWithin(ReuseScope.Container);

			container.Register(c => new EditCustomersPresenter(
					c.Resolve<IEditCustomersView>(),
					c.Resolve<ICustomerRepository>()))
				.ReusedWithin(ReuseScope.Container);


			// Register the launch tasks for the main screen.
			// This is the entry point to our module.
			tasks.Register<IEditCustomersView>("Edit Customers");
		}
	}
}
